package org.core.tliaswebmanagement.service.impl;

import org.core.tliaswebmanagement.mapper.EmpMapper;
import org.core.tliaswebmanagement.mapper.StudentMapper;
import org.core.tliaswebmanagement.pojo.ClazzOption;
import org.core.tliaswebmanagement.pojo.DegreeOption;
import org.core.tliaswebmanagement.pojo.JobOption;
import org.core.tliaswebmanagement.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        List<Map<String,Object>> list =empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(m -> m.get("pos")).toList();
        List<Object> dataList = list.stream().map(m -> m.get("num")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public ClazzOption getStudentCountData() {
        List<Map<String, Object>> clazzList = studentMapper.getStudentCountData();
        List<Object> clazzNameList = clazzList.stream().map(m -> m.get("clazz")).toList();
        List<Object> clazzCountList = clazzList.stream().map(m -> m.get("num")).toList();
        return new ClazzOption(clazzNameList, clazzCountList);
    }
}
